/**
 * 
 */
package edu.pku.sei.modeler.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;

import edu.pku.notation.runtime.draw2d.RoundedRectangleFigure;
import edu.pku.notation.runtime.draw2d.TextFigure;
import edu.pku.sei.modeler.uml.ResourceFactory;

/**
 * @author YanYan
 *
 */
public class SimpleStateFigure extends CommonFigure {

	public static final org.eclipse.swt.graphics.Color ACTION_COLOR = new Color(null,175,178,239);
	public IFigure root = null;
	private TextFigure simpleStateLable = null;
	
	public SimpleStateFigure(){
		super();
		XYLayout xyL = new XYLayout();
		setLayoutManager(xyL);
		setOpaque(false);
		
		root = new RoundedRectangleFigure();
		((RoundedRectangleFigure)root).setCornerHeight(30);
		((RoundedRectangleFigure)root).setCornerWidth(30);
		root.setOpaque(false);
		root.setForegroundColor(ColorConstants.blue);
		add(root);
		
		simpleStateLable = new TextFigure();
		simpleStateLable.setOpaque(false);
		simpleStateLable.setFont(ResourceFactory.getHeadFont());
		simpleStateLable.setForegroundColor(ColorConstants.black);
		simpleStateLable.setBackgroundColor(ColorConstants.white);
		add(simpleStateLable);
		
	}
	
	public void changeLineColor(Color color) {
		this.setForegroundColor(color);
		root.setForegroundColor(color);
	}
	
	protected void paintFigure(Graphics g) {

//		super.paintFigure(g);
		//paintShadow(g);
		g.pushState();
		//g.setForegroundColor(ColorConstants.white);
//		g.fillGradient(getBounds(), true);
		g.fillOval(getBounds());
		g.popState();


	}
	
	public TextFigure getStateLable() {
		return simpleStateLable;
	}
	
	public void setBounds(Rectangle rect) {
		super.setBounds(rect);
		if (root != null)
			root.setSize(rect.width, rect.height);
		if (simpleStateLable != null){
			simpleStateLable.setSize(rect.width, rect.height);//((int)(2.0/3*rect.width), (int)(1.0/2*rect.height));
		}
	}
	protected void paintShadow(Graphics g) {
		// TODO: draw the figure's own shadow here
		super.paintShadow(g);
	}
	
	@Override
	public void changeColor(Color color){
		root.setBackgroundColor(color);
	}
	
}
